// -防抖
export function debounce(fn, wait) {
	let delay = wait || 500
	let timer
	return function() {
		let args = arguments;
		if (timer) {
			clearTimeout(timer)
			console.log('拦截')
		}
		let callNow = !timer
		timer = setTimeout(() => {
			console.log('发送')
			timer = null
		}, delay)
		if (callNow) fn.apply(this, args)
	}
}

// -节流
export function throttle(fn, wait) {
	let delay = wait || 500
	let timer = null
	return function() {
		if (timer) {
			console.log('拦截');
			return
		}
		timer = setTimeout(() => {
			console.log('发送');
			fn.apply(this, arguments)
			timer = null
		}, delay)
	}
}
